import { PetNewBaseView } from "./PetNewBaseView";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { ObjCreate } from "../common/ObjCreate";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { Language } from "../../../../extend/language/Language";
import { PetItem } from "./PetItem";
import { PetTileItem } from "./PetTileItem";
import { ImagesConst } from "../../resource/ImagesConst";
import { PetSkillListPanel } from "./skill/PetSkillListPanel";
import { TimeButton } from "../common/button/TimeButton";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { TilePanel } from "../equipment/TilePanel";
import { DigSkillRenderer } from "./skill/DigSkillRenderer";
import { PublicMessageConfig } from "../../resource/PublicMessageConfig";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { PetColor } from "./info/PetColor";
import { Cache } from "../../cache/Cache";
import { SPetSkill } from "../../../../Message/Game/SPetSkill";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { PetUtil } from "./info/PetUtil";
import { MsgManager } from "../../manager/MsgManager";
import { EPetSkillSoul } from "../../../../Message/Game/EPetSkillSoul";
import { ItemData } from "../../resource/info/ItemData";
import { DigConfirmWindow } from "./skill/DigConfirmWindow";
import { SkillConfig } from "../../resource/SkillConfig";
import { CursorManager } from "../../manager/CursorManager";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
//class PetDigPanel
    
    export  class PetDigPanel extends PetNewBaseView
    {
        constructor()
        {
            super();
            this._skillsProvider = new DataProvider();
            return;
        }

        protected /* override */ init(): void
        {
            var loc1=null;
            ObjCreate.createFlowerBg(0, 0, 582, 125, this);
            ObjCreate.createFlowerBg(475, 126, 107, 274, this);
            ObjCreate.createBg(0, 308, 470, 92, this);
            this.addChild(new GImageBitmap("DigSkillLabel.png", 10, 32));
            this._skillLabel = ObjCreate.createTextField("", 110, 40, 220, 30, this);
            this._skillLabel.htmlText = Language.getString(54444);
            this.addChild(new GImageBitmap("petDigNameBg.png", 400, 10));
            this._petItem = new PetItem();
            this._petItem.isDragAble = false;
            this._petItem.isDropAble = false;
            this._petItem.setSize(48, 48);
            this._petItem.move(417, 15);
            this.addChild(this._petItem);
            this._nameTxt = ObjCreate.createTextField("", 472, 50, 220, 20, this);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tileItem = new PetTileItem();
            this._tileItem.x = 368;
            this._tileItem.y = 25;
            this.addChild(this._tileItem);
            ObjCreate.createBg(3, 70, 576, 50, this, ImagesConst.WindowCenterB);
            this._skillListPanel = new PetSkillListPanel(true);
            this._skillListPanel.x = 8;
            this._skillListPanel.y = 75;
            this._skillListPanel.addEventListener(flash.events.Event.CHANGE, this.onSelectChangeHandler);
            this._skillListPanel.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onSkillMouseOverHandler);
            this._skillListPanel.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onSkillMouseOutHandler);
            this.addChild(this._skillListPanel);
            this.addChild(new GImageBitmap("DigWarehouseLabel.png", 10, 130));
            this._hunLabel = ObjCreate.createTextField("", 110, 140, 220, 30, this);
            this._hunLabel.htmlText = Language.getString(54445);
            this._arrangeBtn = new TimeButton();
            this._arrangeBtn.styleName = "Button";
            this._arrangeBtn.label = Language.getString(54446);
            this._arrangeBtn.setSize(60, 24);
            this._arrangeBtn.move(400, 130);
            this._arrangeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onArrangeBtnClickHandler);
            this.addChild(this._arrangeBtn);
            ObjCreate.createBg(0, 160, 470, 146, this, ImagesConst.WindowCenterB);
            var loc2=0;
            while (loc2 < 30) 
            {
                loc1 = GlobalClass.getBitmap(ImagesConst.PackItemBg);
                loc1.width = 38;
                loc1.height = 38;
                this.addChild(loc1);
                loc1.x = 12 + loc2 % 10 * 45;
                loc1.y = 173 + Math.floor(loc2 / 10) * 41;
                ++loc2;
            }
            this._skillPanel = new TilePanel();
            this._skillPanel.horizontalGap = 0;
            this._skillPanel.verticalGap = 3;
            this._skillPanel.columnWidth = 45;
            this._skillPanel.rowHeight = 38;
            this._skillPanel.setSize(475, 125);
            this._skillPanel.move(13, 174);
            this._skillPanel.setStyle("cellRenderer", DigSkillRenderer);
            this._skillPanel.addEventListener(flash.events.MouseEvent.CLICK, this.onSkillChangeHandler);
            this.addChild(this._skillPanel);
            this.addChild(new GImageBitmap("petDigIcon.png", 500, 170));
            this._rightTipTxt = ObjCreate.createTextField("", 480, 245, 100, 135, this);
            this._rightTipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._rightTipTxt.multiline = true;
            this._rightTipTxt.wordWrap = true;
            this._rightTipTxt.htmlText = Language.getString(54577);
            super.init();
            updateTip(PublicMessageConfig.instance.getPetForgeTextByName("skillDigDesc"), 10, 310, 110, 450);
            return;
        }

        public /* override */ updateByPetInfo(arg1: SPetInfo): void
        {
            this._petInfo = arg1;
            if (arg1) 
            {
                this._petItem.petInfo = arg1;
                this._skillListPanel.petInfo = arg1;
                this._nameTxt.htmlText = PetColor.getColorName(arg1);
                this.updateSkillPanel(Cache.instance.pet.petSkillsDict);
                this._tileItem.petInfo = arg1;
            }
            else 
            {
                this.clear();
            }
            return;
        }

        public updateSkillPanel(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc1=[];
            var loc5=0;
            var loc6=arg1;
            for (loc2 in loc6) 
            {
                loc4 = arg1[loc2] as SPetSkill;
                loc1[int(loc2)] = loc4;
            }
            this._skillsProvider.removeAll();
            loc3 = 0;
            while (loc3 < loc1.length) 
            {
                this._skillsProvider.addItem(loc1[loc3]);
                ++loc3;
            }
            this._skillPanel.dataProvider = this._skillsProvider;
            this._skillPanel.selectedIndex = -1;
            return;
        }

        /* internal  */onArrangeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetSkillTidy));
            return;
        }

        /* internal  */onSelectChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var e: Object /* flash.events.Event */;
            var petSkill: SPetSkill;
            var clickHandler: Function;

            var loc1;
            petSkill = null;
            e = arg1;
            petSkill = this._skillListPanel.selectedSkillInfo;
            if (petSkill) 
            {
                if (PetUtil.isBattled(this._petInfo)) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(54018));
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetCallBackAlert));
                    return;
                }
                if (petSkill.isSoul != EPetSkillSoul._EPetSkillSoulYes) 
                {
                    clickHandler = (arg1: Boolean, arg2: ItemData): void
                    {
                        if (arg1) 
                        {
                            if (arg2) 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.PetSkillSeal, {"petUid": _petInfo.uid, "uid": arg2.uid, "skillId": petSkill.skillId}));
                            }
                        }
                        if (_confirmWindow) 
                        {
                            _confirmWindow.hide();
                        }
                        return;
                    }
                    if (this._confirmWindow == null) 
                    {
                        this._confirmWindow = new DigConfirmWindow();
                    }
                    this._confirmWindow.updateData(petSkill, this._petInfo, clickHandler);
                    this._confirmWindow.show();
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetSkillSeal, {"petUid": this._petInfo.uid, "uid":"", "skillId": petSkill.skillId}));
                }
            }
            return;
        }

        /* internal  */onSkillChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target as DigSkillRenderer;
            var loc2=loc1.petSkill;
            if (loc2) 
            {
                if (SkillConfig.instance.isSpecialSkill(loc2.skillId) && this._petInfo.reinLevel <= 0) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(28028));
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetSkillUnseal, {"petUid": this._petInfo.uid, "pos": loc2.pos}));
            }
            return;
        }

        /* internal  */onSkillMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.showCursor(CursorManager.Soul);
            return;
        }

        /* internal  */onSkillMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.hideCursor();
            return;
        }

        /* internal  */clear(): void
        {
            this._nameTxt.htmlText = Language.getString(54452);
            this._petItem.petInfo = null;
            this._skillListPanel.clear();
            this._tileItem.petInfo = null;
            return;
        }

        /* internal */ /* var */_skillLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_hunLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_skillListPanel: PetSkillListPanel;

        /* internal */ /* var */_arrangeBtn: TimeButton;

        /* internal */ /* var */_skillPanel: TilePanel;

        /* internal */ /* var */_tipText: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_tileItem: PetTileItem;

        /* internal */ /* var */_petItem: PetItem;

        /* internal */ /* var */_rightTipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_confirmWindow: DigConfirmWindow;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_skillsProvider: DataProvider;

        /* internal */ /* var */_shopItemInfo: ShopItemInfo;
    }
